#ifndef HANDLEEQS_H
#define HANDLEEQS_H

/***************************************************************************
				HandleEqs.h
                             -------------------
Copyright (c) 2009-2010 
Author: Kishor D. Bhalerao (kishor8dm@gmail.com)
Contributors: 

This file is associated with the Ph.D. dissertation,"ON METHODS FOR EFFICIENT
AND ACCURATE DESIGN AND SIMULATION OF MULTIBODY SYSTEMS", Bhalerao K.D,
Rensselaer Polytechnic Institute, 2010.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1.) Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2.) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3.) The name of the authors, their employers, or sponsoring organizations may
not be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHORS, THEIR EMPLOYERS, OR SPONSORING ORGANIZATIONS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/

#include "SimTKsimbody.h"
#include "Simbody.h"
#include "DcaDataTypes.h"
#include "SimTKmolmodel.h"
//#include "ThermostatHandleEqs.h"

using namespace SimTK;
using namespace std;

class HandleEqs{
public:
	HandleEqs(MultibodySystem& system, SimbodyMatterSubsystem& matter,State& state, NoseHooverThermostat& Thermo):
	  system_(system),matter_(matter),state_(state),Therm_(Thermo),
		  psi13(new Vec6[matter.getNumBodies()-1]),psi23(new Vec6[matter.getNumBodies()-1]),N_W_K(new Vec3[matter.getNumBodies()-1]){}
	
	~HandleEqs(){delete [] psi13;delete [] psi23;delete [] N_W_K;}

	// Calculate psi_13 and psi_23 at the current time step
	// Does not include mobility forces. Check if the values
	// are set to 0.
	
	void formHandleEquations(const DcaBodyData *Mbs);

	// This method is added Aug 15 2010 by Ali added add the effect of the thermostat to psi13 nad psi23
	void formThermostatHandleEqs(const DcaBodyData *Mbs, const int **FreeJoints );
	
	const Vec6* getpsi13()const {return psi13;}
	const Vec6* getpsi23()const {return psi23;}
	const Vec3* getN_W_K()const {return N_W_K;}

private:
	MultibodySystem& system_;
	SimbodyMatterSubsystem& matter_;
	State& state_;
	NoseHooverThermostat& Therm_;
	
	// Written in Mobilizer Basis
	Vec6 *psi13, *psi23; // psi13 is the array of (numberofbodies -1) pointers which points to the object Vec6 
	Vec3 *N_W_K;
};

#endif